package com.clientmanage.controller;

import com.clientmanage.domain.vo.serviceOrderVo;
import com.clientmanage.domain.resp.PageResult;
import com.clientmanage.domain.resp.Result;
import com.clientmanage.service.IServiceOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 服务订单控制器
 * 实现服务订单管理相关接口
 */
@RestController
@RequestMapping("/service/order")
public class ServiceOrderController {
    @Autowired
    private IServiceOrderService serviceOrderService;

    /**
     * 获取服务订单列表
     * 接口地址：GET /service/order/list
     */
    @GetMapping("/list")
    public Result<PageResult<serviceOrderVo>> getServiceOrderList(
        @RequestParam(required = false) String customerName,
        @RequestParam(required = false) String status,
        @RequestParam(defaultValue = "1") int pageNum,
        @RequestParam(defaultValue = "10") int pageSize
    ) {
        return Result.success(serviceOrderService.pageQuery(customerName, status, null, pageNum, pageSize));
    }

    /**
     * 新增服务订单
     * 接口地址：POST /service/order/add
     */
    @PostMapping("/add")
    public Result<Void> addServiceOrder(@RequestBody serviceOrderVo vo) {
        serviceOrderService.saveOrUpdateServiceOrder(vo);
        return Result.success();
    }

    /**
     * 更新服务订单
     * 接口地址：PUT /service/order/update
     */
    @PutMapping("/update")
    public Result<Void> updateServiceOrder(@RequestBody serviceOrderVo vo) {
        serviceOrderService.saveOrUpdateServiceOrder(vo);
        return Result.success();
    }

    /**
     * 删除服务订单
     * 接口地址：DELETE /service/order/delete/{id}
     */
    @DeleteMapping("/delete/{id}")
    public Result<Void> deleteServiceOrder(@PathVariable String id) {
        serviceOrderService.deleteById(id);
        return Result.success();
    }
}
